﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace QG.JobBack.DAL
{
    public class DbContextFactory<TS> where TS : DbContext, new()
    {
        /// <summary>
        /// 获取数据库唯一的实例
        /// </summary>
        /// <returns></returns>
        public static DbContext GetDbContext()
        {
            var data = CallContext.GetData(typeof(TS).Name) as DbContext;
            if (data != null)
                return data;
            data = new TS();            
            data.Configuration.ProxyCreationEnabled = false;
            CallContext.SetData(typeof(TS).Name, data);
            return data;
        }
    }
}
